package main

import "fmt"

func main() {
	defer fmt.Println("main---1---")
	defer fmt.Println("main---2---")
	fmt.Println("main---3---")
	mytest2(1)
	defer fmt.Println("main---4---")
	fmt.Println("main---5---")
}

func mytest2(num int) {
	defer func() {
		if msg := recover(); msg != nil {
			fmt.Println("panic信息:", msg, "---recover恢复---")
		}
	}()
	defer fmt.Println("mytest---1---")
	defer fmt.Println("mytest---2---")
	fmt.Println("mytest---3---")
	if num == 1 {
		panic("出现异常，抛出panic")
	}
	defer fmt.Println("mytest---4---")
	fmt.Println("mytest---5---")
}
